// pages/component/homes/setpaypsword/setpaypsword.js
var that;
var dataManager = require('../../../../utils/dataManager.js');
var GlobalData = require('../../../../utils/GlobalData.js');

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loginPswd: "",
    firstPswd: '',
    secondPswd: "",
    url: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.url == "setting") {
      this.setData({
        url: "/pages/component/homes/setting/setting"
      })
    } else {
      this.setData({
        url: "/pages/component/homes/purchase/payment/payment"
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("setpaypsword")

  },
  loginPass: function (e) {
    this.setData({
      loginPswd: e.detail.value
    })

  },
  firstPass: function (e) {
    this.setData({
      firstPswd: e.detail.value
    })


  },
  secondPass: function (e) {
    this.setData({
      secondPswd: e.detail.value
    })


  },
  onConfirm() {
    // console.log("修改支付密码");
    if (this.data.loginPswd == "") {
      app.show("请输入登录密码");
      return;
    }
    if (this.data.firstPswd == "" || this.data.secondPswd == "") {
      app.show("请输入支付密码");
      return;
    }
    if (this.data.firstPswd.length != 6 || this.data.secondPswd.length != 6) {
      app.show("请输入6位数字");
      return;
    }
    if (this.data.firstPswd != this.data.secondPswd) {
      app.show("两次密码输入不一样。");
      return;
    }
    dataManager.OnRequestPost({ method: "modifypaypassbypwd", token: GlobalData.token, "password": this.data.loginPswd, "paypass": this.data.firstPswd }, this.onprocessWithoutCode);
  },
  onprocessWithoutCode: function (data) {
    // app.show("设置支付密码成功");
    dataManager.OnRequestPost({ method: "getagent", token: GlobalData.token }, this.onprocessHomeData);
  },
  onprocessHomeData: function (data) {
    GlobalData.homeData = GlobalData.clone(data);
    wx.navigateBack({
      delta: 1
    })
    // app.onTip("设置支付密码成功", this.data.url, true)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})